package uvt.gui.mainframe;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;

import uvt.gui.mainframe.subpanel.PanelAddParent;
import uvt.gui.mainframe.subpanel.addroute.PanelAddRoute;
import uvt.gui.mainframe.subpanel.addsss.PanelAddSSS;
import uvt.gui.mainframe.subpanel.addvehicle.PanelAddVehicle;

public class CreateTransportationNetworkPanel extends JPanel implements ActionListener {
	
	private JPanel panel;
	private static PanelAddParent panelAddParent;
	private ButtonGroup rdbGroup;	
	private JRadioButton rdbVehicle;
	private JRadioButton rdbRoute;
	private static JRadioButton rdbSSS;
	
	public CreateTransportationNetworkPanel() {
		 setBorder(new EmptyBorder(5,5,5,5));
		 setLayout(new GridLayout(2,1));
		 
		 panel = new JPanel(new FlowLayout());
		 panel.setBackground(Color.white);
		 
		 JLabel lblChose = new JLabel("Add:");
		 panel.add(lblChose);
		 
		 rdbGroup = new ButtonGroup();
		 
		 rdbVehicle = new JRadioButton("Vehicles");
		 rdbVehicle.setBackground(Color.white);
		 rdbVehicle.addActionListener(this);
		 rdbVehicle.setSelected(true);
		 rdbGroup.add(rdbVehicle);
		 panel.add(rdbVehicle);
		 
		 rdbRoute = new JRadioButton("Route");
		 rdbRoute.setBackground(Color.white);
		 rdbRoute.addActionListener(this);
		 rdbGroup.add(rdbRoute);
		 panel.add(rdbRoute);
		 
		 rdbSSS = new JRadioButton("Stations,Segments and Streets");
		 rdbSSS.setBackground(Color.white);
		 rdbSSS.addActionListener(this);
		 rdbGroup.add(rdbSSS);
		 panel.add(rdbSSS);
		 
		 add(panel);		
		 
		 panelAddParent = new PanelAddVehicle();
		 add(panelAddParent);		 
		 
	}
	
	public void actionPerformed(ActionEvent ac) {
		remove(panelAddParent);
	    panelAddParent.cleanPanel();		
		if(rdbVehicle.isSelected()) {
			panelAddParent = new PanelAddVehicle();		
		} else if(rdbRoute.isSelected()) {
			panelAddParent = new PanelAddRoute();	
		} else if(rdbSSS.isSelected()) {
			panelAddParent = new PanelAddSSS();
		}
		add(panelAddParent);
		revalidate();		 
	}
	
	public void cleanPanel() {
		panelAddParent.cleanPanel();
	}
	
	public static boolean isSSSPanelSelected() {
		return rdbSSS.isSelected();
	}

}